#!/bin/ksh
PATH=$PATH:/home/oracle/scripts ; export PATH
MSG_LOG=/oracle/backup/log/joblog_`date +%Y%m`.log ;export MSG_LOG
JOBNAME=LTOBackup          ; export JOBNAME

# Set the current month day and year.
month=`date +%m`
day=`date +%d`
year=`date +%Y`

# Add 0 to month. This is a
# trick to make month an unpadded integer.
month=`expr $month + 0`

# Subtract one from the current day.
day=`expr $day - 1`

# If the day is 0 then determine the last
# day of the previous month.
if [ $day -eq 0 ]; then
  
  # Find the preivous month.
  month=`expr $month - 1`  

  # If the month is 0 then it is Dec 31 of
  # the previous year.
  if [ $month -eq 0 ]; then
    month=12
    day=31
    year=`expr $year - 1`  

  # If the month is not zero we need to find
  # the last day of the month.
  else
    case $month in
      1|3|5|7|8|10|12) day=31;;
      4|6|9|11) day=30;;
      2)
        if [ `expr $year % 4` -eq 0 ]; then
          if [ `expr $year % 400` -eq 0 ]; then
            day=29
          elif [ `expr $year % 100` -eq 0 ]; then
            day=28
          else
            day=29
          fi
        else
          day=28
        fi
      ;;
    esac
  fi
fi

if [ $day -lt 10 ]; then
  DateFormat=${year}_${month}_0${day}
  echo $DateFormat
else
  DateFormat=${year}_${month}_${day}
fi
#--------------------
# Backup to Tape
#--------------------
LOG=/home/oracle/lto.out
LTO_FILE=/home/oracle/scripts/LTOSTATUS.bk_20091123
#echo "./oracle/flash_recovery_area/PROD/datafile ./oracle/flash_recovery_area/PROD/archivelog/$DateFormat  ./oracle/flash_recovery_area/PROD/archivelog/`date +%Y`_`date +%m`_`date +%d` ./oracle/flash_recovery_area/PROD/backupset/`date +%Y`_`date +%m`_`date +%d`" > ${LTO_FILE}

MSG_JOB S

cd /
tar cvf /dev/rmt1 `cat ${LTO_FILE}` >>$LOG 2>&1
echo $?
#rm ${LTO_FILE}

MSG_JOB N
